package com.itheima.controller;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentsService studentsService;
    @GetMapping
    public Result findAll(StudentQueryParam studentQueryParam){
        log.info("分页查询,参数:{}",studentQueryParam);
        PageBean pageBean = studentsService.findAll(studentQueryParam);
        return Result.success(pageBean);
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable Integer[] ids){
        log.info("批量删除员工信息:{}",ids);
        studentsService.delete(ids);
        return Result.success( );
    }
    @PostMapping
    public Result add(@RequestBody Student student){
        log.info("新增员工信息:{}",student);
        studentsService.add(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Integer score){
        studentsService.violation(id,score);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfoById(@PathVariable Integer id){
        return Result.success(studentsService.getInfoById(id));
    }
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改员工信息:{}",student);
        studentsService.update(student);
        return Result.success();
    }

}
